package com.eber.demo.design.singleton.lazy;

public class SingletonLazy {
    public static void main(String[] args) {
        System.out.println(Person.getInstance().getName());
    }

    // 这种实现方式是线程安全的
    private static class Person {
        // 私有构造器，防止外界new
        private Person() {
        }

        private static class PersonHolder {
            // PersonHolder（静态内部类）可以访问Person（外部类）
            private static final Person INSTANCE = new Person();
        }

        public static Person getInstance() {
            return PersonHolder.INSTANCE;
        }

        public String getName() {
            return "singleton lazy";
        }
    }
}
